package com.example.timeemail.Dao;

//用于创建和更新数据库

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import androidx.annotation.Nullable;

public class DbHelper extends SQLiteOpenHelper {

    //构造方法，一般用于重写数据库
    public DbHelper(@Nullable Context context) {
        super(context,"user.db",null,1);
    }

    //数据库第一次被创建调用
    @Override
    public void onCreate(SQLiteDatabase db) {
        //初始化数据表
        String sql = "create table user(id integer primary key autoincrement," +
                "username varchar(100) not null," +
                "useremail varchar(100) not null," +
                "password varchar(100) not null," +
                "sex varchar(50)," +
                "age integer," +
                "phone varchar(100))";
        Log.d("数据表user创建",sql);

        db.execSQL(sql);//创建数据库表

    }

    //数据库更新是调用
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
